package com.jzoom.zoom.admin.controllers;

import com.jzoom.zoom.admin.models.DaoService;
import com.jzoom.zoom.caster.codec.Base64;
import com.jzoom.zoom.common.annotations.Inject;
import com.jzoom.zoom.common.json.JSON;
import com.jzoom.zoom.dao.Dao;
import com.jzoom.zoom.web.annotations.Controller;
import com.jzoom.zoom.web.annotations.JsonResponse;
import com.jzoom.zoom.web.annotations.Mapping;
import com.jzoom.zoom.web.annotations.Param;
import com.jzoom.zoom.web.exception.StatusException;

import java.io.UnsupportedEncodingException;
import java.util.Map;

@Controller(key="dbs")
public class DatabaseController {

    @Inject
    private DaoService daoService;

    @Mapping(value = "{ds}")
    @JsonResponse
    public Object query(
            @Param(pathVariable = true)
            String ds,

            String content
    ){
        Dao dao = daoService.getDao(ds);
        Map<String,Object> data;
        try {
            data = JSON.parse(new String(Base64.decode(content),"utf-8"),Map.class);
        } catch (UnsupportedEncodingException e) {
            throw new StatusException.BadRequest();
        }


        return null;
    }

}
